package logic

import (
	"api/internal/svc"
	"api/internal/types"
	"api/service"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type TTSTokenLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewTTSTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TTSTokenLogic {
	return &TTSTokenLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *TTSTokenLogic) TTSToken() (resp *types.ResponseTTSToken, err error) {
	redis := l.svcCtx.RedisPool.Get()
	defer redis.Close()

	commonService := service.NewCommonService(l.ctx, l.svcCtx)
	ret := commonService.GetBaiduTTSToken(redis)

	resp = &types.ResponseTTSToken{}

	resp.Data.ExpiresIn = ret.ExpiresIn
	resp.Data.AccessToken = ret.AccessToken
	resp.Code = 200

	return resp, nil
}
